<!DOCTYPE html>
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layouts/layout">
<head>
</head>
<body>
<div layout:fragment="content">
    <div class="row">
        <div class="col-lg-12">
            <div id="editor">
            </div>
        </div>
        <button id="btn1">提交</button>
    </div>
</div>
<!-- /page content -->
</body>
</html>
<script type="text/javascript" th:src="@{/javascripts/wangEditor-3.1.1/release/wangEditor.min.js}"></script>

<script type="text/javascript">
    $(function () {
        var E = window.wangEditor
        var editor = new E('#editor')
        // 或者 var editor = new E( document.getElementById('editor') )
        editor.customConfig.uploadImgServer = '/upload'
        editor.customConfig.uploadFileName = 'file'
        editor.customConfig.debug = true

        editor.customConfig.showLinkImg = false
        editor.create();
        /*document.getElementById('btn1').addEventListener('click', function () {
            // 读取 html
            alert(editor.txt.html())
        }, false)

        document.getElementById('btn2').addEventListener('click', function () {
            // 读取 text
            alert(editor.txt.text())
        }, false)*/

        $("#btn1").click(function () {
            var htmlStr = editor.txt.html();
            debugger;
            $.ajax({
                url: '/saveEditor',
                type: 'POST',
                data: {editorStr: htmlStr},
                dataType: 'JSON',
                success: function (data) {
                    if(data.code == 0){
                        showSuccessMessage("保存成功！");
                    }else{
                        showErrorMessage("保存出错！");
                    }

                },
                error: function (error) {
                    console.log(error);
                 //   showErrorMessage("保存出错！");
                }
            });
        })

    })
</script>

